/*******************************************************************************
 * Copyright (c) 2005, 2023 IBM Corporation and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package gef.bugs;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.examples.AbstractExample;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.SimpleTextLayout;
import org.eclipse.draw2d.text.TextFlow;

/**
 * Problem scenario - computeSize does not include vertical scrollbar
 */
public class ComputeSizeAndScrolbars extends AbstractExample {

	/**
	 * @see org.eclipse.draw2d.examples.AbstractExample#createContents()
	 */
	@Override
	protected IFigure createContents() {
		FlowPage page = new FlowPage();
		page.setOpaque(true);
		page.setBackgroundColor(ColorConstants.white);
		TextFlow courier = new TextFlow("Courier Courier Courier"); //$NON-NLS-1$
		courier.setLayoutManager(new SimpleTextLayout(courier));
		TextFlow heading = new TextFlow("Heading Heading"); //$NON-NLS-1$
		courier.setFont(COURIER);
		heading.setFont(HEADING_1);
		page.add(courier);
		page.add(heading);
		return page;
	}

	public static void main(String[] args) {
		new ComputeSizeAndScrolbars().run();
	}

	@Override
	protected void setFigureCanvas(FigureCanvas canvas) {
		super.setFigureCanvas(canvas);
		canvas.setVerticalScrollBarVisibility(FigureCanvas.ALWAYS);
		canvas.getViewport().setContentsTracksWidth(true);
	}

}
